package weatherdata;

import java.util.ArrayList;

public class StatisticsDisplay implements Observer, DisplayElement {
	ArrayList<Float> temps;
	ArrayList<Float> hums;
	ArrayList<Float> press;
        //almacenar los segundos
        //ArrayList<Integer> time;
        int time;
	private Subject weatherData;

	public StatisticsDisplay(Subject weatherData) {
		temps = new ArrayList<Float>();
		hums = new ArrayList<Float>();
		press = new ArrayList<Float>();
		this.weatherData = weatherData;
		weatherData.registerObserver(this);
	}

	public void unregister() {
		weatherData.removeObserver(this);
	}

	public void update(float temp, float hum, float pres) {
		this.temps.add(temp);
		this.hums.add(hum);
		this.press.add(pres);
		display();
	}
	
	private float getAverage(){
		float total=0;
		for(Float tem: temps){
			total = total + tem;
		}
		return total/temps.size();
	}
	
	private float getMin(){
		float min = temps.get(0);
		for(Float tem: temps){
			if (tem < min) min = tem;
		}
		return min;
	}
	
	private float getMax(){
		float max = temps.get(0);
		for(Float tem: temps){
			if (tem > max) max = tem;
		}
		return max;
	}

	public void display() {
		System.out.println("++ Avg/Max/Min temperature: " + this.getAverage() + "/" +
				this.getMax() + "/" + this.getMin());
	}

}
